package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.contract.SetPayPwdSecondContract;
import com.sanpu.kxe.business.main.presenter.SetPayPwdSecondPresenter;
import com.sanpu.kxe.common.view.InputPasswordView;
import com.sanpu.kxe.utils.ToastUtil;

import butterknife.Bind;

/**
 * Description：设置支付密码第二步
 * Created by 薛勇军 on 2019/3/20.
 */

public class SetPayPwdSecondActivity extends BaseTitleActivity implements SetPayPwdSecondContract.View {

    @Bind(R.id.content)
    InputPasswordView inputPasswordView;

    private SetPayPwdSecondContract.Presenter mPresenter;

    private String originalPassword;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_set_pay_password;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("支付密码");
        inputPasswordView.setTitle("请再次输入支付密码");

        originalPassword = getIntent().getStringExtra(MainConfig.INTENT_PASSWORD);
        mPresenter = new SetPayPwdSecondPresenter(this);
    }

    @Override
    protected void setListener() {
        super.setListener();
        commonTitle.setLeftOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        inputPasswordView.setOnCompleteClickListener(new InputPasswordView.OnCompleteClickListener() {
            @Override
            public void completeClick(String s) {
                if (!isRespondEvent()) return;
                //验证两次支付是否一致
                if (!TextUtils.equals(originalPassword, s)) {
                    ToastUtil.showTextViewPrompt("两次密码输入不一致，请重新输入");
                    inputPasswordView.clearPsw();
                    return;
                }
                //调接口设置支付密码
                mPresenter.onSetPayPwd(s);
            }
        });
    }

    @Override
    public void clearPwd() {
        inputPasswordView.clearPsw();
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(SetPayPwdSecondContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }

}
